#include <esp_log.h>
#include <esp_err.h>
#include <esp_lcd_panel_ops.h>
#include <esp_lcd_panel_vendor.h>
//#include <esp_lvgl_port.h>
#include <string>
#include <cstdlib>

#include "Display.h"
#include "Board.h"
#include "Application.h"

#define TAG "Display"

Display::Display(int sda_pin, int scl_pin) : sda_pin_(sda_pin), scl_pin_(scl_pin) {
     
}

Display::~Display() {
 
}

void Display::SetText(const std::string &text) {
 
}

void Display::ShowNotification(const std::string &text) {
 
}

void Display::UpdateDisplay() {
    auto chat_state = Application::GetInstance().GetChatState();
    if (chat_state == kChatStateIdle || chat_state == kChatStateConnecting || chat_state == kChatStateListening) {
        std::string text;
        auto& board = Board::GetInstance();
        std::string network_name;
        int signal_quality;
        std::string signal_quality_text;
        if (!board.GetNetworkState(network_name, signal_quality, signal_quality_text)) {
            text = "No network";
        } else {
            text = network_name + "\n" + signal_quality_text;
            if (std::abs(signal_quality) != 99) {
                text += " (" + std::to_string(signal_quality) + ")";
            }
        }

        int battery_voltage;
        bool charging;
        if (board.GetBatteryVoltage(battery_voltage, charging)) {
            text += "\n" + std::to_string(battery_voltage) + "mV";
            if (charging) {
                text += " (Charging)";
            }
        }
        SetText(text);
    }
}
